package bramar.all;




import java.sql.Connection;
import java.sql.DriverManager;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *
 * @author V V P L BRAMARNADH
 */
public class AccessToOracledata {
public AccessToOracledata(String s1) throws ClassNotFoundException, SQLException {
Class.forName("oracle.jdbc.driver.OracleDriver");
Class.forName("org.gjt.mm.mysql.Driver");
Connection ocon=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","scott","tiger");
Connection acon=DriverManager.getConnection("jdbc:mysql:///mydb1","root","root");
Statement st=acon.createStatement();
StringBuffer qry=new StringBuffer();
ResultSet rs=st.executeQuery("select * from "+s1);
qry.append("insert into ");
qry.append(s1);
qry.append(" values(");

ResultSetMetaData rsmd=rs.getMetaData();
	for(int i=1;i<=rsmd.getColumnCount();++i)
			{
			if(i!=1)
                            qry.append(',');
                        qry.append('?');
				 
                        } 
qry.append(")"); 
PreparedStatement ps=ocon.prepareStatement(qry.toString());

while(rs.next())
{
    for(int i=1;i<=rsmd.getColumnCount();++i)
    {
     ps.setString(i,rs.getString(i));
  
    }   
       ps.executeUpdate();
}     
 rs.close();
 st.close();
 ps.close();
 acon.close();
 ocon.close();
 
    }

}
